package com.sooncode.project.focusservice.service;

import com.sooncode.project.core.finder.Finder;
import com.sooncode.project.core.finder.Page;
import com.sooncode.project.focusservice.model.Member;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class SchedulerTask {
    @Scheduled(cron="0 30 0 * * ?")
    public void process(){
        int pageSize=100;
        int pageIndex=0;
        while (true){
            Page<Member> page=new Finder<>(Member.class).page(pageSize,pageIndex);
            for(Member member:page.getContent()){
                try {
                    member.updateAge();
                }catch (Exception ex){
                    ex.printStackTrace();
                }
            }
            if(page.getContent().size()<pageSize)
                break;
            pageIndex++;
        }
    }
}
